package com.tuniu.agents.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Unified API response format
 * @param <T> Data type
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> {
    /**
     * Status code: 0 - success, non-zero - failure
     */
    private Integer code;
    
    /**
     * Response message
     */
    private String message;
    
    /**
     * Response data
     */
    protected T data;
    
    /**
     * Create a successful response
     * @param data The data to be returned
     * @param message The success message
     * @return ApiResponse<T> The successful response
     */
    public static <T> ApiResponse<T> success(T data, String message) {
        return new ApiResponse<>(0, message, data);
    }
    
    /**
     * Create a successful response (no data)
     * @param message The success message
     * @return ApiResponse<T> The successful response
     */
    public static <T> ApiResponse<T> success(String message) {
        return new ApiResponse<>(0, message, null);
    }
    
    /**
     * Create a failure response
     * @param message The error message
     * @return ApiResponse<T> The failure response
     */
    public static <T> ApiResponse<T> error(String message) {
        return new ApiResponse<>(1, message, null);
    }
    
    /**
     * Create a failure response (with error code)
     * @param code The error code
     * @param message The error message
     * @return ApiResponse<T> The failure response
     */
    public static <T> ApiResponse<T> error(Integer code, String message) {
        return new ApiResponse<>(code, message, null);
    }
}